<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <p>收到5000端口发来的信息：<span id="data"></span></p>
  <script>
    function ajax(options, callback) {
      var {url, method} = options
      var xhr = new XMLHttpRequest()
      xhr.withCredentials = true
      xhr.open(method, url, true)
      xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
          console.log(xhr.responseText)
          callback(xhr.responseText)
        }
      }
      xhr.send(null)
    }
    ajax({
      url: 'http://localhost:5000/api/cors',
      method: 'get'
    }, function(msg) {
      document.getElementById('data').innerText = JSON.parse(msg).data
    })
  </script>
</body>
</html>